package com.ruoyi.web.controller.plan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.plan.domain.ReviewPlan;
import com.ruoyi.plan.service.IReviewPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author MLYNDHG
 * @version 1.0
 * @description 复习计划 Controller
 * @date 2023/12/7 16:43
 */
@RestController
@RequestMapping("/plan/review")
public class ReviewPlanController extends BaseController
{
 @Autowired
 private IReviewPlanService reviewPlanService;

 /**
  * 查询复习计划 列表
  */
 @PreAuthorize("@ss.hasPermi('plan:review:list')")
 @GetMapping("/list")
 public TableDataInfo list(ReviewPlan reviewPlan)
 {
  startPage();
  List<ReviewPlan> list = reviewPlanService.selectReviewPlanList(reviewPlan);
  return getDataTable(list);
 }

 /**
  * 导出复习计划 列表
  */
 @PreAuthorize("@ss.hasPermi('plan:review:export')")
 @Log(title = "复习计划 ", businessType = BusinessType.EXPORT)
 @PostMapping("/export")
 public void export(HttpServletResponse response, ReviewPlan reviewPlan)
 {
  List<ReviewPlan> list = reviewPlanService.selectReviewPlanList(reviewPlan);
  ExcelUtil<ReviewPlan> util = new ExcelUtil<ReviewPlan>(ReviewPlan.class);
  util.exportExcel(response, list, "复习计划 数据");
 }

 /**
  * 获取复习计划 详细信息
  */
 @PreAuthorize("@ss.hasPermi('plan:review:query')")
 @GetMapping(value = "/{id}")
 public AjaxResult getInfo(@PathVariable("id") Long id)
 {
  return success(reviewPlanService.selectReviewPlanById(id));
 }

 /**
  * 新增复习计划
  */
 @PreAuthorize("@ss.hasPermi('plan:review:add')")
 @Log(title = "复习计划 ", businessType = BusinessType.INSERT)
 @PostMapping
 public AjaxResult add(@RequestBody ReviewPlan reviewPlan)
 {
  return toAjax(reviewPlanService.insertReviewPlan(reviewPlan));
 }

 /**
  * 修改复习计划
  */
 @PreAuthorize("@ss.hasPermi('plan:review:edit')")
 @Log(title = "复习计划 ", businessType = BusinessType.UPDATE)
 @PutMapping
 public AjaxResult edit(@RequestBody ReviewPlan reviewPlan)
 {
  return toAjax(reviewPlanService.updateReviewPlan(reviewPlan));
 }

 /**
  * 删除复习计划
  */
 @PreAuthorize("@ss.hasPermi('plan:review:remove')")
 @Log(title = "复习计划 ", businessType = BusinessType.DELETE)
 @DeleteMapping("/{ids}")
 public AjaxResult remove(@PathVariable Long[] ids)
 {
  return toAjax(reviewPlanService.deleteReviewPlanByIds(ids));
 }
}
